﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using App_Code;

public partial class product : System.Web.UI.Page
{
    dulieuDataContext db=new dulieuDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadDuLieu();
        }
    }
    protected void LoadDuLieu()
    {
        collect.PageSize =30;
        collect.DataSource =(from o in db.Products
                             where o.Cate_ID == Convert.ToInt32(Request.QueryString["nhom-san-pham"])
                             select o).ToList();
        collect.BindToControl = rpt_san_pham_ban_chay;
        rpt_san_pham_ban_chay.DataSource = collect.DataSourcePaged;

        var catePa =
            (from o in db.Cates where o.Cate_ID== Convert.ToInt32(Request.QueryString["nhom-san-pham"])&&o.TypeCateID==2 select o.Parent).Take(1).SingleOrDefault();
        lblnhomtincha.Text = (from o in db.Cates where o.Cate_ID == catePa select o.Name).SingleOrDefault();
        lblnhomtincon.Text =
            (from o in db.Cates where o.Cate_ID == Convert.ToInt32(Request.QueryString["nhom-san-pham"]) select o.Name).
                SingleOrDefault();
    }
    protected void BuyClick(object s, CommandEventArgs e)
    {
        var idpr = e.CommandName;
        var cart = (Cart)Session["cart"];
        if (cart == null)
        {
            cart = new Cart();
        }
        cart.AddPro(idpr, 1);
        Session.Add("cart", cart);
        Response.Write("<SCRIPT language='JavaScript'>alert('Đã thêm vào giỏ hàng!');</SCRIPT> ");

    }
}